package com.itboye.textileexpes.repository;

import java.lang.reflect.Type;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.interfaces.IUserRepository;
import com.itboye.textileexpes.beans.BuyBean;
import com.itboye.textileexpes.beans.PersonDataBean;
import com.itboye.textileexpes.json.ByJsonRequest.Builder;
import com.itboye.textileexpres.base.BaseErrorListener;
import com.itboye.textileexpres.base.BaseNetRepository;
import com.itboye.textileexpres.base.BaseSuccessReqListener;

public class UserRepository extends BaseNetRepository implements
		IUserRepository<PersonDataBean> {

	public static String LoginByPwd = "BY_User_login";// 用户登陆（正常登录）
	public static String RegisterService = "By_User_register";// 注册账号
	public static String FindPwdByPhone = "BY_User_findPswByMobile";// 找回密码（通过手机号码找回）
	public static String UpdateUserInfo = "BY_User_update";// 修改用户信息
	// private HttpUtils utils;
	public static String BindPhoneNumber = "BY_User_bind";// 绑定手机号码
	public static String UpdatePwdByPwd = "BY_User_updatePsw";// 修改密码（通过原密码修改）
	public static String UpdateBindPhoneNumber = "BY_User_changePhone";// 修改绑定手机
	public static String LoginByVer = "BY_User_loginByCode";// 通过验证码登录
	public static String LoginByWx = "BY_Weixin_login";// 通过微信登录
	public static String WxPay = "BY_Wxpay_preOrder";// 微信预支付
	public static String testPay = "BY_Orders_testPaySuc";// 测试支付
	public static String PayNow = "BY_Orders_payNow";// 订单支付新
	public static String LoginByCode="By_User_loginByCode";//短信验证登录
	String api = "100";

	public UserRepository() {

	}

	public UserRepository(ICompleteListener listener) {
		this.setListener(listener);
	}

	/*
	 * @see
	 * com.itboye.mengwu.data.interfaces.IUserRepository#register(java.lang.
	 * Object) 2016-4-21 hebidu
	 */
	@Override
	public void register(PersonDataBean model) {
		// Type type = new TypeToken<RigisterModel>() {
		// }.getType();
		// String apiVer = "101";
		// Map<String, Object> params = new HashMap<String, Object>();
		//
		// params.put("username", model.getUsername());
		// params.put("password", model.getPassword());
		// params.put("reg_type", 3);
		// params.put("code", model.getYanzhengma());
		// // Builder<PersonDataBean> builder = new Builder<PersonDataBean>();
		//
		// // 目前最简化调用
		// // START
		// (new Builder<RigisterModel>())
		// .setTypeVerParamsAndReturnClass(RegisterService, apiVer,
		// params, type)
		// .requestListener(
		// new BaseSuccessReqListener<RigisterModel>(getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
		// // end
	}

	/*
	 * 登录
	 * 
	 * @see
	 * com.itboye.mengwu.data.interfaces.IUserRepository#login(java.lang.Object)
	 * 2016-4-21 hebidu
	 */

	@Override
	public void login(PersonDataBean model) {

		// String apiVer = api;
		// Map<String, Object> params = new HashMap<String, Object>();
		//
		// if (model.getType() == 0) {// 账号密码登录
		// params.put("username", model.getUsername());
		// params.put("password", model.getPassword());
		//
		// // Builder<PersonDataBean> builder = new Builder<PersonDataBean>();
		//
		// // 目前最简化调用
		// // START
		// (new Builder<PersonDataBean>())
		// .setTypeVerParamsAndReturnClass(LoginByPwd, apiVer, params,
		// PersonDataBean.class)
		// .requestListener(
		// new BaseSuccessReqListener<PersonDataBean>(
		// getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
		// } else if(model.getType()==1){// 短信验证码登录
		// params.put("mobile", model.getUsername());
		// params.put("code", model.getPassword());
		// (new Builder<PersonDataBean>())
		// .setTypeVerParamsAndReturnClass(LoginByVer, apiVer, params,
		// PersonDataBean.class)
		// .requestListener(
		// new BaseSuccessReqListener<PersonDataBean>(
		// getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
		// }else if(model.getType()==2){// 微信登录
		// params.put("code", model.getPassword());
		// (new Builder<PersonDataBean>())
		// .setTypeVerParamsAndReturnClass(LoginByWx, apiVer, params,
		// PersonDataBean.class)
		// .requestListener(
		// new BaseSuccessReqListener<PersonDataBean>(
		// getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
		// }
		// // end

	}

	/*
	 * @see
	 * com.itboye.mengwu.data.interfaces.IBaseRepository#update(java.lang.Object
	 * ) 2016-4-21 hebidu
	 */
	@Override
	public void update(PersonDataBean model) {
		// String apiVer = api;
		// Type type = new TypeToken<WXBindModel>() {
		// }.getType();
		// Map<String, Object> params = new HashMap<String, Object>();
		// switch (model.getType()) {
		// case 1:
		// params.put("mobile", model.getUsername());
		// params.put("psw", model.getPassword());
		// params.put("code", model.getYanzhengma());
		// (new Builder<String>())
		// .setTypeVerParamsAndReturnClass(FindPwdByPhone, apiVer,
		// params, String.class)
		// .requestListener(
		// new BaseSuccessReqListener<String>(getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
		// break;
		// case 2:
		// params.put("uid", model.getUid());
		// params.put("nickname", model.getNickname());
		// params.put("sex", model.getSex());
		// params.put("sign", model.getSign());
		// (new Builder<String>())
		// .setTypeVerParamsAndReturnClass(UpdateUserInfo, apiVer,
		// params, String.class)
		// .requestListener(
		// new BaseSuccessReqListener<String>(getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
		// break;
		// case 3:// 通过手机号码更换绑定手机
		// params.put("uid", model.getUid());
		// params.put("password", model.getPassword());
		// params.put("mobile", model.getMobile());
		// params.put("code", model.getYanzhengma());
		// (new Builder<WXBindModel>())
		// .setTypeVerParamsAndReturnClass(UpdateBindPhoneNumber,
		// apiVer, params, type)
		// .requestListener(
		// new BaseSuccessReqListener<WXBindModel>(getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
		// case 4:// 第一次绑定手机号码
		// params.put("uid", model.getUid());
		// params.put("code", model.getYanzhengma());
		// params.put("mobile", model.getMobile());
		// params.put("password", model.getMobile());
		// (new Builder<WXBindModel>())
		// .setTypeVerParamsAndReturnClass(BindPhoneNumber, apiVer,
		// params, type)
		// .requestListener(
		// new BaseSuccessReqListener<WXBindModel>(getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
		// break;
		// case 5:// 通过密码修改密码
		// params.put("uid", model.getUid());
		// params.put("old_psw", model.getPassword());
		// params.put("psw", model.getNewPwd());
		// (new Builder<String>())
		// .setTypeVerParamsAndReturnClass(UpdatePwdByPwd, apiVer,
		// params, String.class)
		// .requestListener(
		// new BaseSuccessReqListener<String>(getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
		//
		// default:
		// break;
		// }

	}

	/*
	 * @see
	 * com.itboye.mengwu.data.interfaces.IBaseRepository#getInfo(java.lang.Object
	 * ) 2016-4-21 hebidu
	 */
	@Override
	public void getInfo(PersonDataBean model) {
		// TODO Auto-generated method stub

	}

	/*
	 * @see
	 * com.itboye.mengwu.data.interfaces.IBaseRepository#add(java.lang.Object)
	 * 2016-4-21 hebidu
	 */
	@Override
	public void add(PersonDataBean model) {

		throw new UndeclaredThrowableException(new Throwable("该方法未实现!"));

	}

	/*
	 * @see
	 * com.itboye.mengwu.data.interfaces.IBaseRepository#delete(java.lang.Object
	 * ) 2016-4-21 hebidu
	 */
	@Override
	public void delete(PersonDataBean model) {
		throw new UndeclaredThrowableException(new Throwable("该方法未实现!"));
	}

	/*
	 * @see
	 * com.itboye.mengwu.data.interfaces.IBaseRepository#query(java.lang.Object)
	 * 2016-4-21 hebidu
	 */
	@Override
	public List<PersonDataBean> query(PersonDataBean model) {
		throw new UndeclaredThrowableException(new Throwable("该方法未实现!"));
	}

	@Override
	public void wxPay(String orderCode, String totalPrice, String desc) {
		// // TODO Auto-generated method stub
		// Type type = new TypeToken<WeChatBean>() {
		// }.getType();
		// String apiVer = "100";
		// Map<String, Object> params = new HashMap<String, Object>();
		//
		// params.put("code", orderCode);
		// params.put("total_price", totalPrice);
		// params.put("desc", desc);
		// // Builder<PersonDataBean> builder = new Builder<PersonDataBean>();
		//
		// // 目前最简化调用
		// // START
		// (new Builder<WeChatBean>())
		// .setTypeVerParamsAndReturnClass(WxPay, apiVer,
		// params, type)
		// .requestListener(
		// new BaseSuccessReqListener<WeChatBean>(getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
		//
		// }
		//
		// @Override
		// public void testPay(String uid, String code) {
		// // TODO Auto-generated method stub
		// Type type = new TypeToken<String>() {
		// }.getType();
		// String apiVer = "100";
		// Map<String, Object> params = new HashMap<String, Object>();
		//
		// params.put("code", code);
		// params.put("uid",uid);
		// // 目前最简化调用
		// // START
		// (new Builder<String>())
		// .setTypeVerParamsAndReturnClass(testPay, apiVer,
		// params, type)
		// .requestListener(
		// new BaseSuccessReqListener<String>(getListener()))
		// .errorListener(new BaseErrorListener(getListener()))
		// .desEncodeThenBuildAndSend();
	}

	@Override
	public void payNow(String uid, String orderCode, String payType,
			String payMoney) {
		// TODO Auto-generated method stub

		Type type = new TypeToken<BuyBean>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> params = new HashMap<String, Object>();

		params.put("order_code", orderCode);
		params.put("uid", uid);
		params.put("pay_type", payType);
		params.put("pay_money", payMoney);
		// 目前最简化调用
		// START
		(new Builder<BuyBean>())
				.setTypeVerParamsAndReturnClass(PayNow, apiVer, params, type)
				.requestListener(
						new BaseSuccessReqListener<BuyBean>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void testPay(String uid, String code) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> params = new HashMap<String, Object>();

		params.put("code", code);
		params.put("uid", uid);
		// 目前最简化调用
		// START
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(testPay, apiVer, params, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void onLoginByCode(String country, String mobile, String code) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("country", country);
		params.put("mobile", mobile);
		params.put("code", code);
		// 目前最简化调用
		// START
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(LoginByCode, apiVer, params, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

}
